package com.spring.demo10.eg1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MapPropertySource;

import java.util.Map;

/**
 * @author vhans
 */
public class Test {

    @org.junit.Test
    public void test() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

        Map<String, Object> mailInfoForDb = DbUtil.getMailInfoForDb();
        // 将其丢在MapPropertySource中（MapPropertySource类是spring提供的一个类，是PropertySource的子类）
        MapPropertySource mailSource = new MapPropertySource("mail", mailInfoForDb);
        // 将mailPropertySource丢在Environment中的PropertySource列表的第一个中，让优先级最高
        context.getEnvironment().getPropertySources().addFirst(mailSource);

        context.register(MainConfig2.class);
        context.refresh();
        System.out.println(context.getBean(MailConfig.class));
    }
}
